from race.Player import *
import logging.config
from threadJob import *
from pynput.mouse import Controller as mController
from pynput.keyboard import Controller as kController
from pynput.keyboard import Key
import functools
import datetime

logging.config.fileConfig('./util/logging.conf')
log = logging.getLogger("example")

"""
    子类描述：
        1、武僧坦克类
"""


class DruidTank(Player):

    def on_keyboard_press_son_before_thread(self, key):
        log.debug("on_keyboard_press_son_before_thread 1:进入了函数")
        # 有些按键是直接终止别人的，继续自己的，有些不是这样的，因此要区别对待【排列组合，情况非常多】/【也要超级符合每个职业的操作习惯】
        if key in (
                Key.f1, Key.f2, Key.f3, Key.f4, Key.f5, Key.f6, Key.f7, Key.f8, Key.f9, Key.f10, Key.f11,
                Key.f12):
            pass
        elif key == Key.enter:
            pass
        elif key == Key.space:
            pass
        elif key == Key.alt_l:
            pass
        elif key == Key.ctrl_l:
            pass
        elif key == Key.caps_lock:
            pass
        elif key == Key.shift_l:
            pass
        elif key.char == 'a':
            # 不终止别人，后面让只允许一个线程执行的逻辑来顺序排
            # ★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|
            # 并行并发执行的折中方案【通过触发其他按键，这样的好处是线程池统一管理了】
            # self.kb.press('r')
            # self.kb.release('r')
            #
            # self.kb.press('b')
            # self.kb.release('b')
            pass
        elif key.char == 'z':
            pass
        elif key.char == 'q':
            pass
        elif key.char == 'w':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'r':
            # 终止掉别人
            # interruptAllByForce()
            pass
        elif key.char == 'g':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'x':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'v':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'h':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'c':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'e':
            pass
        elif key.char == 's':
            pass
        elif key.char == 'd':
            pass
        elif key.char == 'f':
            pass
        elif key.char == 'b':
            pass
        return

    # 执行父类的方法
    # @logAop
    def a(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        # super().a()
        self.kb.press('`')  # 触发-->parallel1
        self.kb.release('`')

        self.kb.press(Key.alt_l)
        self.kb.release(Key.alt_l)

        self.kb.press(Key.ctrl_l)
        self.kb.release(Key.ctrl_l)

        self.kb.press(Key.caps_lock)
        self.kb.release(Key.caps_lock)

        curr_time = datetime.datetime.now()

        while True:
            # 狂暴回复
            self.pubAvgColorTiggerKeyAndStopClickTwice(454, self.WABloodBarY, self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, self.WABloodBarAvgColor, 'r', 'small',
                                                       '7', 0.1, 6, 25, self.WA_SQUARE_ZFX,
                                                       self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, 'r', 0, 'small')
            self.pubAvgColorTiggerKeyAndStopClickTwice(497, self.WABloodBarY, self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, self.WABloodBarAvgColor, 'r', 'small',
                                                       '7', 0.1, 6, 25, self.WA_SQUARE_ZFX,
                                                       self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, 'r', 0, 'small')
            # ××××这次狂暴回复最重要，避免连续点击两次，后面绵节约一次狂暴回复××××
            self.pubAvgColorTiggerKeyAndStopClickTwice(536, self.WABloodBarY, self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, self.WABloodBarAvgColor, 'r', 'small',
                                                       '7', 0.5, 6, 25, self.WA_SQUARE_ZFX,
                                                       self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, 'r', 0, 'small')

    def on_mouse_click_son_before_thread(self, x, y, button, pressed):
        # 在鼠标点击，终止和打断其他动作（有些职业需要，有些不需要）??????????
        pass
        return

    def mouseRightClick(self, x, y):
        log.debug('★圣骑士坦克，鼠标click-right，需要开始执行的内容★')
        return

    def parallel1(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        while self.ui.stopLoop == False:
            self.click(self.kb, '1', 8)
            sleep(0.1)
            self.click(self.kb, '2', 8)
            sleep(0.1)
            self.click(self.kb, '3', 4)
            # sleep(0.2)
            # self.click(self.kb, '5', 2)
            # self.click(self.kb, '0', 1)
        return

    def parallelAlt2(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        while self.ui.stopLoop == False:
            # 铁鬃
            self.click(self.kb, '6', 8)
            # 树皮
            self.pubAvgColorTiggerKeyBloodBarMode(540, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, 'r', 'small', 'k', 0.06, 2)
            # 万灵之召
            self.pubAvgColorTiggerKeyBloodBarMode(540, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, 'r', 'small', '5', 0.06, 2)
            # self.click(self.kb, '5', 3)
            # 防止狂暴恢复出bug1
            # 生存本能
            self.pubAvgColorTiggerKeyBloodBarMode(523, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, 'r', 'small', '8', 0.06, 2)
            # 生存本能
            self.pubAvgColorTiggerKeyBloodBarMode(479, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, 'r', 'small', '8', 0.06, 2)
            # 饰品
            self.pubAvgColorTiggerKeyBloodBarMode(479, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, 'r', 'small', 'k', 0.06, 2)
        return

    def parallelCap3(self):
        # Cap--3
        while True:
            sleep(1)
            # 甘鬙 30%
            self.pubAvgColorTiggerKeyBloodBarMode(455, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, 'r', 'small', 't', 0.1, 8)
            # # 补狂暴回复

    def w(self):
        for i in range(1, 3):
            self.click(self.kb, '7', 3)
            sleep(0.3)
        return

    def q(self):
        for i in range(1, 7):
            self.click(self.kb, 'p', 3)
            sleep(0.3)
        return

    def x(self):
        for i in range(1, 4):
            self.click(self.kb, 'i', 2)
            sleep(0.2)

        # 打断后的继续
        self.click(self.kb, 'a', 1)
        return

    def mouseUp(self, x, y):
        for i in range(1, 14):
            self.click(self.kb, 'o', 3)
            sleep(0.3)
        return

    def mouseDown(self, x, y):
        for i in range(1, 14):
            self.click(self.kb, '5', 3)
            sleep(0.3)
        return


class HealDruid(Player):

    def mouseUp(self, x, y):
        # AOE 抬团血
        # sleep(1.1)
        # 美德道标必须出来
        # self.click(self.kb, '4', 2)

        while True:
            # self.pubAvgColorCDNumberDeductInBlock(814, 944, 15, 15, 'g', 0, '4', 'b', 100)
            self.click(self.kb, '6', 8)
            sleep(0.3)
            self.click(self.kb, '2', 3)

    def mouseDown(self, x, y):
        # 单体抬血
        while True:
            self.click(self.kb, '2', 3)
            sleep(0.3)

    def a(self):
        self.click(self.kb, '1', 3)
        sleep(1)
        self.click(self.kb, '1', 3)
        sleep(1)
        self.click(self.kb, '4', 2)

    def mouseRightClick(self, x, y):
        # 53,250           -->966,836
        # 在某块区域的点击，才生效，否咋就是不生效的，应为在其他区域的点击，可能在做其他的动作。
        if x > 53 and x < 818 and y > 250 and y < 836:
            self.click(self.kb, '1', 3)
            sleep(1)
            self.click(self.kb, '1', 3)
            sleep(1)
            self.click(self.kb, '4', 2)
            print('生日:' + str(x) + ':' + str(y))
        return

    def on_mouse_scroll_son_before_thread(self, dx, dy):
        if dy < 0:
            # 滚轮向下
            self.interruptAllByForceMouseUpDown()  # 强制打断正在运行的循环
        elif dy > 0:
            # 滚轮向上
            self.interruptAllByForceMouseUpDown()  # 强制打断正在运行的循环
        return

    def space(self):
        # self.click(self.kb, Key.tab, 1)
        self.click(self.kb, ']', 3)
        return

    # def f(self):
    #     #self.click(self.kb, Key.tab, 1)
    #     self.click(self.kb, '8', 6)
    #     return

    def q(self):
        for i in range(1, 4):
            self.click(self.kb, '4', 6)
        return

    def parallel1(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        for i in range(1, 888888):
            sleep(0.2)
            self.click(self.kb, 'i', 3)
            sleep(0.2)
            self.click(self.kb, 'k', 3)
        return

    def parallelAlt2(self):
        # 父类的方法先执行（或者后续看看是不是就直接用之类覆盖之后的方法）
        for i in range(1, 888888):
            # sleep(0.01)
            # self.click(self.kb, 't', 3)
            # sleep(0.01)
            sleep(1)
            pass


if __name__ == '__main__':
    pass
